<?php
session_start();
header('Content-type: text/html; charset=utf-8');

@mysql_connect ('localhost','root','root');

    if(mysql_errno()){
        die(mysql_error());
    }
    mysql_select_db('bolgme');
    mysql_set_charset('utf8');
    $sql = "select name,pass from haoyou where `name` = '$_GET[name]' and `pass` = '$_GET[pass]'";  
$id = $_GET['name'];
$_SESSION['name']=$id;
  // var_dump($_SESSION['name']);die;
    $result = mysql_query($sql); 
    $num = mysql_num_rows($result);//函数返回结果集中行的数目
    if($num){  
            $row = mysql_fetch_array($result); //函数从结果集中取得一行作为关联数组
            echo '<script>alert("登录成功！");window.location.href="index.php"</script>';
        }else{  
            echo "<script>alert('用户名或密码不正确！');history.go(-1);</script>";  
            } 
 mysql_close();
?>